import 'package:crm/page/Login/crm_login_page.dart';
import 'package:flutter/material.dart';
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:scoped_model/scoped_model.dart';

import 'package:crm/constant/constant.dart';
import 'package:crm/model/main_scoped_model.dart';
import 'package:crm/tools/shared_preferences_util.dart';
import 'package:crm/page/home_page.dart';

const String AppName = 'CRM';

void main() {
  runApp(MyApp());
  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle =
        SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
}

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  // 创建顶层状态管理层
  MainModel _mainModel = MainModel();

  void loadAsync() async {
    await SpUtil.getInstance(); //等待Sp初始化完成
  }

  @override
  void initState() {
    super.initState();
    loadAsync();
  }

  @override
  Widget build(BuildContext context) {
    return ScopedModel(
      model: _mainModel,
      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        title: AppName,
        theme: ThemeData(
          primaryColor: Colors.white,
          scaffoldBackgroundColor: AppColors.PageBackgroundColor,
        ),
        home: HomePage(),
      ),
    );
  }
}
